package com.truyentranh.modules.ohvui;

import com.truyentranh.R;
import com.truyentranh.utils.Logger;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.Display;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

@SuppressLint("SetJavaScriptEnabled")
public class OhVuiCommentActivity extends Activity{
	
	WebView webView;
	LinearLayout loadingProcess;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		Bundle extras = getIntent().getExtras();
		String value = "";
		if (extras != null) {
		    value = extras.getString("IMAGE_ID");
		    Logger.logMe("value = "+value);
		}
		
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);		
		this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(R.layout.haivl_activity_comment_layout);	
		
		webView = (WebView)findViewById(R.id.webViewComment);
		loadingProcess = (LinearLayout)findViewById(R.id.loadingProcessComment);
		loadingProcess.setVisibility(View.VISIBLE);
		
		String url = "https://www.facebook.com/plugins/comments.php?api_key=132707493449375&locale=vi_VN&sdk=joey&" +
				"channel_url=http://static.ak.facebook.com/connect/xd_arbiter.php?version=18&cb=f33232cf6&" +
				"origin=http://www.ovui.vn/f306155228&domain=www.ovui.vn&relation=parent.parent&numposts=10&width=720&" +
				"href="+value;
		
		if(webView != null){
			webView.setVisibility(View.INVISIBLE);
			webView.loadUrl(url);
			webView.setPadding(0, 0, 0, 0);
			webView.setInitialScale(100);
			webView.getSettings().setJavaScriptEnabled(true);
			webView.setWebViewClient(chromeClient);
		}
		
		TextView textView = (TextView) findViewById(R.id.titleActivity);
		textView.setText("Bình luận");

		Button moreFunction = (Button) findViewById(R.id.btnMoreFunctions);
		moreFunction.setVisibility(View.GONE);
		Button back = (Button) findViewById(R.id.btnBackAcvitity);
		if (back != null) {
			back.setOnClickListener(new OnClickListener() {

				public void onClick(View v) {
					finish();
				}
			});
		}
	}
	
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
			finish();
			return true;
		}

		return super.onKeyDown(keyCode, event);
	}

	
	WebViewClient chromeClient = new WebViewClient(){
		
		public void onPageFinished(WebView view, String url) {
			loadingProcess.setVisibility(View.GONE);
			webView.setVisibility(View.VISIBLE);
		};
	};
}
